package com.home.duy.GUI;


import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JInternalFrame;

import com.home.Common.Common;
import com.home.Common.Resources_Duy;
import com.home.Entity.Ban;
import com.home.Entity.KhuVucBan;
import com.home.Validation.Validator;
import com.home.duy.code.DAO.BanDAO;
import com.home.duy.code.DAO.KhuVucBanDAO;
import com.home.duy.code.FileFilter.ImageFileFilter;
import com.home.duy.code.Helper.UtilsFileImage;
import com.home.duy.code.components.ImageBackground;
import com.home.duy.code.components.ImageFileView;
import com.home.duy.code.components.Panel;
import com.home.duy.code.components.PanelDisplayBan;

import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.GridBagLayout;
import java.awt.ScrollPane;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.AccessControlException;
import java.security.AccessController;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JToggleButton;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.ButtonUI;
import javax.swing.JTextPane;
import javax.swing.JEditorPane;
import java.awt.GridBagConstraints;

public class QuanLyKhuVuc extends JInternalFrame {

	private BufferedImage imgCurrent = null;
	private String extImg = "";
	private KhuVucBan object = null;
	private int statusXoa = 0;  //  @jve:decl-index=0:

	private static final int FORM_WIDTH = 800;

	private static final int FORM_HEIGHT = 550;

	private ParentFrame parent;

	private JPanel jContentPane = null;

	private JPanel panelListKV = null;

	private JPanel PanelThongTinKV = null;

	private JScrollPane ScrollPaneListKV = null;

	private JList listKV = null;

	private JLabel imgKV = null;

	private JLabel jLabel = null;

	private JTextField txtTenKV = null;

	private JLabel jLabel1 = null;

	private JRadioButton rdbHoatDong = null;

	private JRadioButton rdbNgungHoatDong = null;

	private ButtonGroup btnGroup;

	private JLabel jLabel2 = null;

	private JPanel panelCommand = null;

	private JToggleButton btnThemKV = null;

	private JToggleButton btnCapNhatKV = null;

	private JButton btnXoaKV = null;

	private JTextArea txtMoTa = null;

	private JScrollPane scrollPaneTxtMoTa = null;

	private JPanel panelImg = null;

	private JLabel jLabel3 = null;

	private JPanel panelBtnChange = null;

	private JButton btnChange = null;
	private JPanel panelBan = null;
	/**
	 * This is the xxx default constructor
	 */
	public QuanLyKhuVuc(ParentFrame parent) {
		super();
		btnGroup = new ButtonGroup();
		this.parent = parent;
		initialize();
		getDataForListKV();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		// this.setSize(FORM_WIDTH, FORM_HEIGHT);
		this.setSize(new Dimension(800, 550));
		this.setContentPane(getJContentPane());
		int w = FORM_WIDTH;
		int h = FORM_HEIGHT;
		// this.setBounds((parent.getWidthDesktopPane()-w)/2 ,
		// (parent.getHeightDesktopPane()-h)/2, w, h);
		this.setTitle(Resources_Duy.TITLE_MENU_ITEM_KHUVUC.toUpperCase());
		this.setClosable(true);
		this.setIconifiable(true);
		statusComponent(false);
	}

	// =================== PROCESS METHOD ======================

	@SuppressWarnings("unchecked")
	private List<KhuVucBan> getAllKV() {
		List<KhuVucBan> kvb = null;
		try {
			KhuVucBanDAO kvbDao = new KhuVucBanDAO();
			kvb = kvbDao.findAll(KhuVucBan.class);
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(),"Lỗi",JOptionPane.ERROR_MESSAGE);
		}
		
		return kvb;
	}

	private void getDataForListKV() {
		try {
			Vector<KhuVucBan> vkb = new Vector<KhuVucBan>();
			for (KhuVucBan k : getAllKV()) {
				vkb.add(k);
			}
			listKV.setListData(vkb);
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, "Quá Trình Nạp Dữ Liệu Có Lỗi",
					"Lỗi", JOptionPane.ERROR_MESSAGE);
		}

	}

	private void processSelectListKV() {
		try {
			if (listKV.getSelectedValue() != null) {
				object = (KhuVucBan) listKV.getSelectedValue();
				statusXoa = 1;
				txtTenKV.setText(object.getTen());
				getPanelBan().removeAll();
				loadBanOfKV();
				
				
				if (object.isTinhTrang()) {
					rdbHoatDong.setSelected(true);
				} else {
					rdbNgungHoatDong.setSelected(true);
				}
				txtMoTa.setText(object.getMoTa());
				ImageIcon ic = null;
				try {
					File f = new File(Resources_Duy.PATH_SAVE_IMAGE
							+ object.getHinhAnh());
					if (f.exists())
					{
						BufferedImage img = Common.getBufferImage(f);
						int type = img.getType() == 0 ? BufferedImage.TYPE_INT_ARGB
								: img.getType();

						BufferedImage imgRe = Common.getImageResized(img, type,
								Resources_Duy.WIDTH_IMG_RESIZE,
								Resources_Duy.HEIGHT_IMG_RESIZE);

						ic = Common.convertBufferImageToImageIcon(imgRe);
					}
					else
						ic = Common.getImageIcon(Resources_Duy.IMAGE_DEFAULT);
				} catch (NullPointerException e) {
					ic = Common.getImageIcon(Resources_Duy.IMAGE_DEFAULT);
				}
				

				imgKV.setIcon(ic);

			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "Lỗi",
					JOptionPane.ERROR_MESSAGE);
		}

	}

	private void resetAllField() {
		txtTenKV.setText("");
		txtMoTa.setText("");
		imgKV.setIcon(Common.getImageIcon(Resources_Duy.IMAGE_DEFAULT));
		rdbHoatDong.setSelected(true);

	}

	private void processBtnThem() {
		if (btnThemKV.isSelected()) {
			btnThemKV.setText("CHẤP NHẬN");
			btnXoaKV.setText("HỦY BỎ");
			statusComponent(true);
			resetAllField();
			txtTenKV.requestFocus();
			btnCapNhatKV.setEnabled(false);
			listKV.setEnabled(false);
			statusXoa = 2;
		} else {
			try {
				if (validation()) {
					KhuVucBan kvb = new KhuVucBan();
					KhuVucBanDAO kvbDao = new KhuVucBanDAO();

					kvb.setMaSo(Common.getID());
					kvb.setTen(txtTenKV.getText().trim());
					if (rdbHoatDong.isSelected())
						kvb.setTinhTrang(true);
					else
						kvb.setTinhTrang(false);
					kvb.setMoTa(txtMoTa.getText().trim());
					if (imgCurrent != null) {
						kvb.setHinhAnh(Common.getNameOfImage(kvb.getMaSo(),
								extImg));
					}

					if (kvbDao.saveOrUpdate(kvb)) {
						JOptionPane.showMessageDialog(this,
								"Đã Thêm Mới Thành Công !", "Thông Báo",
								JOptionPane.INFORMATION_MESSAGE);
						listKV.setEnabled(true);
						if (imgCurrent != null) {
							Common.writeImgToFile(
									imgCurrent,
									extImg.substring(1),
									Resources_Duy.PATH_SAVE_IMAGE
											+ kvb.getHinhAnh());
						}
						resetAllField();
						statusComponent(false);
						refestListKV();
						btnCapNhatKV.setEnabled(false);
						btnXoaKV.setEnabled(false);
						imgCurrent = null;
						extImg = "";
						btnXoaKV.setText("XÓA");
						statusXoa = 1;
					} else
						JOptionPane.showMessageDialog(this, "Có Lỗi Xảy Ra !",
								"Lỗi", JOptionPane.ERROR_MESSAGE);
				} else {
					btnThemKV.setSelected(true);
					return;
				}
			} catch (Exception e) {
				JOptionPane.showMessageDialog(this, e.getMessage(), "Lỗi",
						JOptionPane.ERROR_MESSAGE);
				return;
			}
			btnThemKV.setText("THÊM");

		}

	}

	private void statusComponent(boolean flag) {
		// jLabel.setEnabled(flag);
		// jLabel1.setEnabled(flag);
		// jLabel2.setEnabled(flag);
		// txtTenKV.setEnabled(flag);
		txtTenKV.setEditable(flag);
		rdbHoatDong.setEnabled(flag);
		rdbNgungHoatDong.setEnabled(flag);
		// txtMoTa.setEnabled(flag);
		txtMoTa.setEditable(flag);
		btnChange.setEnabled(flag);
		btnCapNhatKV.setEnabled(flag);
		btnXoaKV.setEnabled(flag);
		// imgKV.setEnabled(flag);
	}

	private void processChangeImage() {
		try {
			Common.tranformJFileChooserToVi();
			JFileChooser fileChooser = new JFileChooser();
			fileChooser.addChoosableFileFilter(new ImageFileFilter());
			fileChooser.setFileView(new ImageFileView());

			int returnVal = fileChooser.showOpenDialog(this);
			if (returnVal == JFileChooser.APPROVE_OPTION) {
				File fileImg = fileChooser.getSelectedFile();
				// imgCurrent = Common.getBufferImage(file)

				BufferedImage img = Common.getBufferImage(fileImg);
				int type = img.getType() == 0 ? BufferedImage.TYPE_INT_ARGB
						: img.getType();

				BufferedImage imgRe = Common.getImageResized(img, type,
						Resources_Duy.WIDTH_IMG_RESIZE,
						Resources_Duy.HEIGHT_IMG_RESIZE);

				ImageIcon ic = Common.convertBufferImageToImageIcon(imgRe);
				imgKV.setIcon(ic);
				imgCurrent = img;
				extImg = Common.getExtension(fileImg.getName());

				// BufferedImage img = Common.getBufferImage(fileImg);
				// ResampleOp resampleOp = new ResampleOp(160, 160);
				// BufferedImage imgBuff = resampleOp.filter(img, null);
				// ImageIcon ic = Common.convertBufferImageToImageIcon(imgBuff);
				// imgKV.setIcon(ic);
			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "Lỗi",
					JOptionPane.ERROR_MESSAGE);
		}
	}

	private boolean validation() {
		boolean check = true;
		if (Validator.isBlank(txtTenKV.getText())) {
			check = false;
			JOptionPane.showMessageDialog(this, "Bạn Hãy Nhập Tên Khu Vực !",
					"Thông Báo", JOptionPane.INFORMATION_MESSAGE);
			txtTenKV.requestFocus();
			// btnThemKV.setSelected(true);
		}
		return check;
	}

	private void refestListKV() {
		getDataForListKV();
	}

	private void processCapNhatKV() {
		try {
			if (btnCapNhatKV.isSelected()) {
				statusComponent(true);
				listKV.setEnabled(false);
				btnCapNhatKV.setText("CHẤP NHẬN");
				btnXoaKV.setText("HỦY BỎ");
				btnThemKV.setEnabled(false);
				statusXoa = 3;
			} else {
				
				listKV.setEnabled(true);
				btnCapNhatKV.setText("CẬP NHẬT");
				statusComponent(true);
				btnThemKV.setEnabled(true);

				if (object != null) {
					KhuVucBanDAO kvbDao = new KhuVucBanDAO();
					if (validation()) {
						object.setTen(txtTenKV.getText().trim());
						if (rdbHoatDong.isSelected())
							object.setTinhTrang(true);
						else
							object.setTinhTrang(false);
						object.setMoTa(txtMoTa.getText().trim());
						if (imgCurrent != null) {
							object.setHinhAnh(object.getMaSo() + extImg);
							File f = new File(Resources_Duy.PATH_SAVE_IMAGE+object.getHinhAnh());
							if(f.exists())
							{
								f.delete();
								Common.writeImgToFile(
										imgCurrent,
										extImg.substring(1),
										Resources_Duy.PATH_SAVE_IMAGE
												+ object.getHinhAnh());
							}
							else
							{
								Common.writeImgToFile(
										imgCurrent,
										extImg.substring(1),
										Resources_Duy.PATH_SAVE_IMAGE
												+ object.getHinhAnh());
							}
						}

						if (kvbDao.saveOrUpdate(object)) {
							JOptionPane.showMessageDialog(this,
									"Đã Cập Nhật Thành Công !", "Thông Báo",
									JOptionPane.INFORMATION_MESSAGE);
							imgCurrent = null;
							extImg = "";
							statusComponent(false);
							btnCapNhatKV.setEnabled(true);
							btnXoaKV.setEnabled(true);
							btnXoaKV.setText("XÓA");
							statusXoa = 1;
						}
						else
						{
							JOptionPane.showMessageDialog(this, "Đã Có Lỗi Xảy Ra !", "Lỗi",
									JOptionPane.ERROR_MESSAGE);
						}
					}
				}
			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "Lỗi",
					JOptionPane.ERROR_MESSAGE);
		}

	}
	
	private void processBtnXoa()
	{
		KhuVucBanDAO kvbDao = new KhuVucBanDAO();
		switch (statusXoa) {
		case 1:
		{
			try {
				BanDAO banDao = new BanDAO();
				List<Ban> list = banDao.findByKVB(object.getMaSo());
				for(Iterator<Ban> it = list.iterator();it.hasNext();)
					{
						Ban ban = (Ban)it.next();
						ban.setKhuVucBan(null);
						banDao.saveOrUpdate(ban);
					}
				if(kvbDao.delete(object))
				{
					JOptionPane.showMessageDialog(this, "Đã Xóa Thành Công !","Thông Báo",JOptionPane.INFORMATION_MESSAGE);
					File f = new File(Resources_Duy.PATH_SAVE_IMAGE+object.getHinhAnh());
					f.delete();
					
					
					
					refestListKV();
					resetAllField();
					statusComponent(false);
					btnThemKV.setEnabled(true);
				}
			} catch (Exception e) {
				JOptionPane.showMessageDialog(this, e.getMessage(),"Lỗi",JOptionPane.ERROR_MESSAGE);
			}
			break;
		}
		case 2 :
		{
			
			resetAllField();
			statusComponent(false);
			btnThemKV.setSelected(false);
			btnThemKV.setText("THÊM");
			btnThemKV.setEnabled(true);
			listKV.setEnabled(true);
			btnXoaKV.setText("XÓA");
			statusXoa = 1;
			break;
		}
		case 3 :
		{
			//resetAllField();
			statusComponent(false);
			btnCapNhatKV.setSelected(false);
			btnCapNhatKV.setText("CẬP NHẬT");
			btnCapNhatKV.setEnabled(true);
			btnXoaKV.setEnabled(true);
			btnThemKV.setEnabled(true);
			listKV.setEnabled(true);
			btnXoaKV.setText("XÓA");
			statusXoa = 1;
			txtTenKV.setText(object.getTen());
			if(object.isTinhTrang())
				rdbHoatDong.setSelected(true);
			else
				rdbNgungHoatDong.setSelected(true);
			txtMoTa.setText(object.getMoTa());
			
			ImageIcon ic = null;
			try {
				File f = new File(Resources_Duy.PATH_SAVE_IMAGE
						+ object.getHinhAnh());
				if (f.exists())
				{
					BufferedImage img = Common.getBufferImage(f);
					int type = img.getType() == 0 ? BufferedImage.TYPE_INT_ARGB
							: img.getType();

					BufferedImage imgRe = Common.getImageResized(img, type,
							Resources_Duy.WIDTH_IMG_RESIZE,
							Resources_Duy.HEIGHT_IMG_RESIZE);

					ic = Common.convertBufferImageToImageIcon(imgRe);
				}
				else
					ic = Common.getImageIcon(Resources_Duy.IMAGE_DEFAULT);
			} catch (NullPointerException e) {
				ic = Common.getImageIcon(Resources_Duy.IMAGE_DEFAULT);
			}
			

			imgKV.setIcon(ic);
			
			break;
		}
		default:
			break;
		}
	}
	
	private void loadBanOfKV()
	{
		try {
			if(object != null)
			{
				BanDAO banDao = new BanDAO();
				List<Ban> list = banDao.findByKVB(object.getMaSo());
				for(Iterator<Ban> it = list.iterator();it.hasNext();)
				{
					Ban ban = (Ban)it.next();
					
					PanelDisplayBan p = new PanelDisplayBan();
					
					getPanelBan().add(p);
				}
			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(),"Lỗi",JOptionPane.ERROR_MESSAGE);
		}
		
	}

	// =================== END PROCESS METHOD ==========================

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getPanelListKV(), null);
			jContentPane.add(getPanelThongTinKV(), null);
			jContentPane.add(getPanelCommand(), null);
			jContentPane.add(getPanelBan(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes panelListKV
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelListKV() {
		if (panelListKV == null) {
			panelListKV = new JPanel();
			panelListKV.setLayout(null);
			panelListKV.setBounds(new Rectangle(10, 10, 201, 462));
			panelListKV.setBorder(BorderFactory
					.createTitledBorder("DANH SÁCH KHU VỰC"));
			panelListKV.add(getScrollPaneListKV(), null);
		}
		return panelListKV;
	}

	/**
	 * This method initializes PanelThongTinKV
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelThongTinKV() {
		if (PanelThongTinKV == null) {
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(226, 127, 55, 20));
			jLabel2.setText("Mô Tả : ");
			jLabel2.setFont(jLabel2.getFont().deriveFont(Font.BOLD));
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(226, 76, 93, 23));
			jLabel1.setText("Tình Trạng : ");
			jLabel1.setFont(jLabel1.getFont().deriveFont(Font.BOLD));
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(225, 42, 91, 22));
			jLabel.setText("Tên Khu Vực : ");
			jLabel.setFont(jLabel.getFont().deriveFont(Font.BOLD));
			PanelThongTinKV = new JPanel();
			PanelThongTinKV.setLayout(null);
			PanelThongTinKV.setBounds(new Rectangle(220, 10, 556, 274));
			PanelThongTinKV.setBorder(BorderFactory
					.createTitledBorder("THÔNG TIN CHI TIẾT KHU VỰC"));
			PanelThongTinKV.add(jLabel, null);
			PanelThongTinKV.add(getTxtTenKV(), null);
			PanelThongTinKV.add(jLabel1, null);
			PanelThongTinKV.add(getRdbHoatDong(), null);
			PanelThongTinKV.add(getRdbNgungHoatDong(), null);
			PanelThongTinKV.add(jLabel2, null);
			PanelThongTinKV.add(getScrollPaneTxtMoTa(), null);
			PanelThongTinKV.add(getPanelImg(), null);
		}
		return PanelThongTinKV;
	}

	/**
	 * This method initializes ScrollPaneListKV
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getScrollPaneListKV() {
		if (ScrollPaneListKV == null) {
			ScrollPaneListKV = new JScrollPane();
			ScrollPaneListKV.setBounds(new Rectangle(8, 23, 186, 430));
			ScrollPaneListKV.setViewportView(getListKV());
		}
		return ScrollPaneListKV;
	}

	/**
	 * This method initializes listKV
	 * 
	 * @return javax.swing.JList
	 */
	private JList getListKV() {
		if (listKV == null) {
			listKV = new JList();
			listKV.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			listKV.addListSelectionListener(new ListSelectionListener() {

				@Override
				public void valueChanged(ListSelectionEvent arg0) {
					// statusComponent(true);
					btnChange.setEnabled(false);
					btnCapNhatKV.setEnabled(true);
					btnThemKV.setEnabled(true);
					btnXoaKV.setEnabled(true);
					processSelectListKV();

				}
			});
		}
		return listKV;
	}

	/**
	 * This method initializes imgKV
	 * 
	 * @return javax.swing.JPanel
	 */
	private JLabel getImgKV() {
		if (imgKV == null) {
			imgKV = new JLabel();
			imgKV.setLayout(new GridBagLayout());
			imgKV.setBounds(new Rectangle(16, 27, 160, 160));
			imgKV.setIcon(Common.getImageIcon(Resources_Duy.IMAGE_DEFAULT));
		}
		return imgKV;
	}

	/**
	 * This method initializes txtTenKV
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTxtTenKV() {
		if (txtTenKV == null) {
			txtTenKV = new JTextField();
			txtTenKV.setBounds(new Rectangle(330, 36, 208, 27));

		}
		return txtTenKV;
	}

	/**
	 * This method initializes rdbHoatDong
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getRdbHoatDong() {
		if (rdbHoatDong == null) {
			rdbHoatDong = new JRadioButton("Đang Họat Động");
			rdbHoatDong.setBounds(new Rectangle(328, 79, 155, 21));
			btnGroup.add(rdbHoatDong);
		}
		return rdbHoatDong;
	}

	/**
	 * This method initializes rdbNgungHoatDong
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getRdbNgungHoatDong() {
		if (rdbNgungHoatDong == null) {
			rdbNgungHoatDong = new JRadioButton("Ngưng Hoạt Động");
			rdbNgungHoatDong.setBounds(new Rectangle(328, 111, 158, 23));
			btnGroup.add(rdbNgungHoatDong);
		}
		return rdbNgungHoatDong;
	}

	/**
	 * This method initializes panelCommand
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelCommand() {
		if (panelCommand == null) {
			panelCommand = new JPanel();
			panelCommand.setLayout(null);
			panelCommand.setBorder(BorderFactory.createTitledBorder(""));
			panelCommand.setBounds(new Rectangle(221, 289, 556, 49));
			panelCommand.add(getBtnThemKV(), null);
			panelCommand.add(getBtnCapNhatKV(), null);
			panelCommand.add(getBtnXoaKV(), null);
		}
		return panelCommand;
	}

	/**
	 * This method initializes btnThemKV
	 * 
	 * @return javax.swing.JButton
	 */
	private JToggleButton getBtnThemKV() {
		if (btnThemKV == null) {
			btnThemKV = new JToggleButton();
			btnThemKV.setBounds(new Rectangle(13, 10, 115, 27));
			btnThemKV.setText("THÊM");
			btnThemKV.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					processBtnThem();
				}
			});
		}
		return btnThemKV;
	}

	/**
	 * This method initializes btnCapNhatKV
	 * 
	 * @return javax.swing.JButton
	 */
	private JToggleButton getBtnCapNhatKV() {
		if (btnCapNhatKV == null) {
			btnCapNhatKV = new JToggleButton();
			btnCapNhatKV.setBounds(new Rectangle(223, 10, 115, 27));
			btnCapNhatKV.setText("CẬP NHẬT");
			btnCapNhatKV.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent arg0) {
					processCapNhatKV();
				}
			});
		}
		return btnCapNhatKV;
	}

	/**
	 * This method initializes btnXoaKV
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtnXoaKV() {
		if (btnXoaKV == null) {
			btnXoaKV = new JButton();
			btnXoaKV.setBounds(new Rectangle(426, 10, 115, 27));
			btnXoaKV.setText("XÓA");
			btnXoaKV.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					processBtnXoa();
				}
			});
		}
		return btnXoaKV;
	}

	/**
	 * This method initializes txtMoTa
	 * 
	 * @return javax.swing.JTextArea
	 */
	private JTextArea getTxtMoTa() {
		if (txtMoTa == null) {
			txtMoTa = new JTextArea();
			// txtMoTa.setBounds(new Rectangle(232, 159, 309, 74));
		}
		return txtMoTa;
	}

	/**
	 * This method initializes scrollPaneTxtMoTa
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getScrollPaneTxtMoTa() {
		if (scrollPaneTxtMoTa == null) {
			scrollPaneTxtMoTa = new JScrollPane();
			scrollPaneTxtMoTa.setBounds(new Rectangle(226, 162, 312, 92));
			scrollPaneTxtMoTa.setViewportView(getTxtMoTa());
		}
		return scrollPaneTxtMoTa;
	}

	/**
	 * This method initializes panelImg
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelImg() {
		if (panelImg == null) {
			jLabel3 = new JLabel();
			jLabel3.setText("Hình Ảnh");
			jLabel3.setFont(jLabel3.getFont().deriveFont(Font.BOLD));
			jLabel3.setBounds(new Rectangle(1, 1, 190, 25));
			jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
			jLabel3.setOpaque(true);
			jLabel3.setBackground(new Color(77, 122, 153));
			jLabel3.setForeground(Color.WHITE);
			panelImg = new JPanel();
			panelImg.setLayout(null);
			panelImg.setBounds(new Rectangle(19, 36, 192, 216));
			panelImg.add(jLabel3, null);
			panelImg.add(getImgKV(), null);
			Border borderLine = BorderFactory.createLineBorder(new Color(77,
					122, 153));
			
			panelImg.setBorder(borderLine);
			panelImg.add(getPanelBtnChange(), null);
		}
		return panelImg;
	}

	/**
	 * This method initializes panelBtnChange
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelBtnChange() {
		if (panelBtnChange == null) {
			panelBtnChange = new JPanel();
			panelBtnChange.setLayout(null);
			panelBtnChange.setBounds(new Rectangle(1, 188, 190, 27));
			panelBtnChange.setOpaque(true);
			panelBtnChange.setBackground(new Color(77, 122, 153));
			Border borderLine = BorderFactory.createLineBorder(new Color(77,
					122, 153));
			panelBtnChange.setBorder(borderLine);
			panelBtnChange.add(getBtnChange(), null);

		}
		return panelBtnChange;
	}

	/**
	 * This method initializes btnChange
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtnChange() {
		if (btnChange == null) {
			btnChange = new JButton();
			btnChange.setBounds(new Rectangle(52, 1, 88, 25));
			btnChange.setText("Thay Đổi");
			btnChange.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent arg0) {
					processChangeImage();
				}
			});
		}
		return btnChange;
	}

	/**
	 * This method initializes panelBan	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getPanelBan() {
		if (panelBan == null) {
			panelBan = new JPanel();
			panelBan.setLayout(new FlowLayout());
			panelBan.setBounds(new Rectangle(223, 349, 553, 132));
		}
		return panelBan;
	}

} // @jve:decl-index=0:visual-constraint="10,10"
